<template>
  <div style="width: 100%; height: 105px; background: #ffffff; margin: 0 auto">
    <div
      style="
        width: 95%;
        height: 100px;
        margin: 0 auto;
        display: flex;
        align-items: center;
        justify-content: flex-end;
      "
    >
      <div
        @click="importResources"
        style="
          width: 210px;
          height: 46px;
          line-height: 46px;
          background: #4381e6;
          border-radius: 4px;
          font-size: 18px;
          color: #ffffff;
          cursor: pointer;
          text-align: center;
        "
      >
        {{ $t("improtRes.confirm") }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "ImportResButton",
  props: {
    importParentResources: Function,
  },
  methods: {
    importResources() {
      let selected = JSON.parse(
        window.localStorage.getItem("selected-resources")
      );
      let result = { detail: selected };
      result.detail.map((item) => {
        (item.resUrl = item.resourceUrl),
          (item.modelName = item.resourceName),
          (item.photo = item.resourceIcon),
          (item.priceRange = item.price),
          (item.resSize = item.resourceSize),
          (item.modelNo = item.resourceNo),
          (item.buySize = item.remainUseTimes),
          (item.resMd5 = item.resourceMd5),
          (item.modelId = item.resourceId),
          (item.authType = 0),
          (item.resSource = 1);
        delete item.resourceIcon;
        delete item.resourceName;
        delete item.resourceMd5;
        delete item.resourceSize;
        delete item.remainUseTimes;
        delete item.resourceNo;
        delete item.resourceUrl;
        delete item.resourceId;
        delete item.price;
      });
      // console.log(result.detail.length !== 0);
      // if (result.detail.length !== 0) {
      //   //确认弹窗，传值给编辑器并清空列表
      //   this.$alert(
      //     "您当前的资源导入图书项目不扣费，当图书发布三审通过后自动扣费",
      //     {
      //       confirmButtonText: "确定",
      //       callback: (action) => {
      //         if (action === "confirm") {
      //           this.importParentResources(JSON.stringify(result));
      //           this.$store.commit("resources/clearAllSelectedRes");
      //         }
      //       },
      //     }
      //   );
      // }
      this.importParentResources(JSON.stringify(result));
      this.$store.commit("resources/clearAllSelectedRes");
    },
  },
};
</script>

<style scoped>
</style>
